<template>
  <div>
    <!-- <van-nav-bar title="账号登录" left-text="" left-arrow @click-left="onClickLeft" /> -->
    <TopNav :title="title"></TopNav>
    <van-form @submit="onSubmit">
      <van-field v-model="username" name="username" placeholder="请输入账号" :rules="[{ required: true, message: '请填写用户名' }]" />
      <van-field v-model="password" type="password" name="password" placeholder="请输入密码" :rules="[{ required: true, message: '请填写密码' }]" />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit">登录</van-button>
      </div>
    </van-form>
    <a class="go">还没有账号，去注册~</a>
  </div>
</template>

<script>
import TopNav from '@/components/TopNav.vue'
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'
export default {
  data () {
    return {
      // hzhmqd
      title: '账号登录',
      username: '',
      password: ''
    }
  },
  components: {
    TopNav
  },
  methods: {
    async onSubmit (values) {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      const { body } = await login(values)
      setToken(body.token)
      this.$toast.success('登录成功')
      this.$router.push('/')
    }
  }
}
</script>

<style lang="less" scoped>
// .van-nav-bar {
//   background-color: RGB(33,185,122);
//   /deep/ .van-icon {
//     color: #fff;
//   }
//   /deep/ .van-nav-bar__title {
//     color: #fff;
//   }
// }
/deep/ .van-cell {
  margin: 15px 0;
}
.go {
  color: #666;
  margin-left: 30%;
  font-size: 14px;
}
</style>
